package com.winning.ds.login.service.impl;

import com.winning.ds.login.service.DbsxService;
import com.winning.ds.login.dao.DbsxMapper;
import com.winning.ds.login.entity.SysDbsxbEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName DbsxServiceImpl
 * @Description TODO
 * @Author WJX
 * @Date 2020/4/8 15:31
 **/
@Service
public class DbsxServiceImpl implements DbsxService {

    @Autowired
    private DbsxMapper dbsxMapper;

    @Override
    public Map<String, Object> getDbsxData(String dbsql) {

        return dbsxMapper.getDbsxData(dbsql);
    }

    @Override
    public List<SysDbsxbEntity> getDbsxList(List<String> cdbmList) {
        return dbsxMapper.getListByCdbm(cdbmList);
    }

    @Override
    public Map<String, String> formatResult(SysDbsxbEntity dbsxb,Map<String, Object> map) {
        Map<String,String> result = new HashMap<>();
        //记录数
        String sjl = map.get("JLS")+"";
        //距离当前时间量
        String timeBetween = getSj(map);

        result.put("jls",sjl);
        result.put("timeBetween",timeBetween);
        result.put("msg",dbsxb.getXxnr());
        result.put("cdbm",dbsxb.getCdbm());
        return result;
    }

    private String getSj(Map<String, Object> map){
        if(null == map || map.isEmpty()){
            return "当天";
        }
        String year = map.get("年")+"";
        String mon = map.get("月")+"";
        String week = map.get("周")+"";
        String day = map.get("日")+"";
        if(StringUtils.isNotBlank(year) && !"0".equals(year)){
            return year + "年前";
        }
        if(StringUtils.isNotBlank(mon) && !"0".equals(mon)){
            return mon + "周前";
        }

        if(StringUtils.isNotBlank(week) && !"0".equals(week)){
            return week + "周前";
        }

        if(StringUtils.isNotBlank(day)){
            return "0".equals(day) ?  "当天": (day + "天前");
        }
        return "当天";
    }
}
